package tt.dz.order.service.rpc.rpchander;

import org.apache.avro.generic.GenericRecord;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import tt.dz.order.exception.BusinessException;
import tt.dz.order.service.OrderService;
import tt.dz.order.vo.OrderInfoVo;
import tt.dz.order.vo.RetVO;

@Component("findOrderItemsByOrderNoHander")
public class FindOrderItemsByOrderNoHander implements BaseHander {
	private static Logger log = LoggerFactory.getLogger(FindOrderItemsByOrderNoHander.class);
	@Autowired
	OrderService orderService;

	@Override
	public RetVO dohander(GenericRecord req) {
		RetVO retVO = new RetVO(RetVO.SuccessCode, null, null);
		// 根据订单号查询订单项
		try {
			String reqStr = req.get("orderNo").toString();
			log.info("根据订单号查询订单项reqStr：" + reqStr);
			if (StringUtils.isBlank(reqStr)) {
				throw new BusinessException("根据订单号查询订单项，订单号为空");
			}
			OrderInfoVo orderInfoVo = orderService.getOrderInfo(reqStr);
			retVO.setBizData(orderInfoVo);
		} catch (Exception e) {
			log.error("根据订单号查询订单项发生异常", e);
			retVO.setRetCode(RetVO.FailCode);
			retVO.setResultCode("1020300");
			retVO.setErrorMsg(e.getMessage());
		}
		return retVO;
	}

}
